package com.link.base.base.project.controller;

import com.link.base.base.project.model.PartAnnualSale;
import com.link.base.base.project.service.PartAnnualSaleService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 零件类型年度销售额表
 *
 * @author 王昊
 * @date 2021-05-07 14:34:55
 */
@Controller
@RequestMapping("/link/partAnnualSale")
public class PartAnnualSaleController extends BasicController<PartAnnualSale> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private PartAnnualSaleService partAnnualSaleService;

    @Override
    public BasicService<PartAnnualSale> getBasicService() throws Exception {
        return partAnnualSaleService;
    }

    /**
     * 前20车企各零件销售额分析（饼图）
     */
    @RequestMapping(value = "/partSalesCompReport",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> partSalesCompReport(@JsonParam PartAnnualSale entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            List<PartAnnualSale> partAnnualSales = partAnnualSaleService.queryAllByYearAcct(entity);
            result.put("success",true);
            //将cha返回
            result.put("newRow",partAnnualSales);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }

    /**
     * 前20畅销车型各零件销售额分析（饼图）
     */
    @RequestMapping(value = "/partSalesCarModelReport",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> partSalesCarModelReport(@JsonParam PartAnnualSale entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            List<PartAnnualSale> partAnnualSales = partAnnualSaleService.queryAllByYearCarModel(entity);
            result.put("success",true);
            //将cha返回
            result.put("newRow",partAnnualSales);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }

    /**
     * 各零件类型年度销售额分析（嵌套环形图）
     */
    @RequestMapping(value = "/totalPartAnnualReport",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> totalPartAnnualReport(@JsonParam PartAnnualSale entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            List<PartAnnualSale> partAnnualSales = partAnnualSaleService.queryAllByYear(entity);
            result.put("success",true);
            //将cha返回
            result.put("newRow",partAnnualSales);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }
}